package com.xuetang9.t9.xinhuaxia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.User;
import com.xuetang9.t9.xinhuaxia.beans.UserOrderlist;
import com.xuetang9.t9.xinhuaxia.mappers.UserOrderlistMapper;
import com.xuetang9.t9.xinhuaxia.service.IUserOrderListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/3/4 12:15
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@Service
@Resource(name = "userOrderlistMapper")
public class UserOrderListService implements IUserOrderListService {
    @Autowired
    private UserOrderlistMapper userOrderlistMapper;
    @Override
    public boolean insert(UserOrderlist userOrderlist) {
        return userOrderlistMapper.insertSelective(userOrderlist)>0;
    }

    @Override
    public boolean remove(Long id) {
        return userOrderlistMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean update(UserOrderlist userOrderlist) {
        return userOrderlistMapper.updateByPrimaryKeySelective(userOrderlist)>0;
    }

    @Override
    public UserOrderlist queryById(Long id) {
        return userOrderlistMapper.queryById(id);
    }

    @Override
    public UserOrderlist queryByProperty(UserOrderlist userOrderlist) {
        return userOrderlistMapper.selectOne(userOrderlist);
    }

    @Override
    public List<UserOrderlist> queryByUserId(Long id) {
        return userOrderlistMapper.queryByUserId(id);
    }

    @Override
    public PageInfo<UserOrderlist> queryByPage(int currentPage, int perPageSize) {
        PageHelper.startPage(currentPage,perPageSize);
        PageHelper.orderBy("uo_orderId desc");
        List<UserOrderlist> userOrderlists = userOrderlistMapper.queryAll();
        PageInfo<UserOrderlist> pageInfo = new PageInfo<>(userOrderlists);
        return pageInfo;
    }
}
